<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@include file="/WEB-INF/jspf/must/basePath.jspf" %>
<!--后台UI组件Start-->
<%@include file="/WEB-INF/jspf/zj/ligerui/LigerUI.jspf" %>
<%--<%@include file="/WEB-INF/jspf/zj/ligerui/LigerUI_form.jspf" %>--%>
<!--后台UI组件End-->
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>JSP Page</title>
        <script type="text/javascript">
//-------------------------------全局变量-------------------------------------------------
            var UPDATE;
            var GRID, GRID2;
            var ADD;
            $(function() {
                GRID = $("#divID_GRID").ligerGrid({
                    columns: [
                        {display: '订单号', name: 'order_code', width: 100, align: 'left'}
                        , {display: '房间', name: 'room_code', width: 40, align: 'left'}
                        , {display: '开单时间', name: 'order_time', width: 111, align: 'left'}
                        , {display: '状态', name: 'order_sort', width: 37, align: 'left', render: function(data) {
                                switch (data.order_sort) {
                                    case "0":
                                        return "<h5>待付</h5>";
                                    case "1":
                                        return "已付";
                                    case "2":
                                        return "开立";
                                }
                            }}
                        , {display: '打印', name: 'order_print', width: 22, align: 'left'}
                        , {display: 'id', name: 'order_id', hide: true}
                    ]
                    , usePager: false
                    , url: 'view/buy/order/manager/fwy/s/selectMJZ.imy'
                    , width: '320'
                    , height: '100%'
                    , onSelectRow: f_viewOrderB
                });
                GRID2 = $("#divID_GRID2").ligerGrid({
                    columns: [
                        {display: '类型', name: 'source_sort', width: 37, align: 'left', render: function(data) {
                                switch (data.source_sort) {
                                    case "1":
                                        return "菜谱";
                                    case "2":
                                        return "活动";
                                    case "3":
                                        return "套餐";
                                }
                            }}
                        , {display: '菜名', name: 'buy_name', width: 90, align: 'left'}
                        , {display: '价格', name: 'buy_price', width: 40, align: 'left'}
                        , {display: '数量', name: 'buy_number', width: 30, align: 'left'}
                        , {display: '上台数量', name: 'orderb_lock_number', width: 30, align: 'left'}
                        , {display: '总额', name: 'buy_sum', width: 40, align: 'left'}
                        , {display: '状态', name: 'orderb_style', width: 36, align: 'left', render: function(data) {
                                switch (data.orderb_style) {
                                    case 1:
                                        return "未定";
                                    case 2:
                                        return "锁定";
                                    case 3:
                                        return "制作";
                                    case 4:
                                        return "完结";
                                }
                                return data.orderb_style;
                            }}
                        , {display: 'id', name: 'orderb_id', hide: true}
                        , {display: '操作', width: 170, align: 'left', render: function(data) {
                                if (data.buy_number >= 0) {
                                    switch (data.orderb_style) {
                                        case 2:
                                            {
                                                return "<button onclick=\"f_dellFWYOrderB('" + data.order_id + "','" + data.orderb_id + "')\">删除</button>"
                                            }
                                        default:
                                            {
                                                return "<button onclick=\"f_lockmyfood('" + data.order_id + "','" + data.orderb_id + "',1)\">+上菜</button>"
                                                        + "<button onclick=\"f_lockmyfood('" + data.order_id + "','" + data.orderb_id + "',-1)\">-上菜</button>｜"
                                                        + "<button onclick=\"f_backmyfood('" + data.orderb_id + "','" + data.order_id + "','" + data.source_id + "')\">退菜</button>";
                                            }
                                    }
                                } else {
                                    return "<button onclick=\"f_dellBackFood('" + data.order_id + "','" + data.orderb_id + "')\">取消退菜</button>";
                                }
                            }}
                    ]
                    , usePager: false
                    , url: 'view/buy/order/manager/fwy/s/selectOneB.imy'
                    , width: '485'
                    , height: '100%'
                });

                $("#toptoolbar").ligerToolBar({items: [
                        {text: '开单', click: add}
                        , {line: true}
                        , {text: '修改', click: update}
                        , {line: true}
                        , {text: '删单', click: dell}
                    ]});
                setInterval(eventFWY, 2000);

                function eventFWY() {
                    $.post("view/buy/order/manager/fwy/event/selectAll.imy", {}, function(fwye) {
                        var str = "";
                        var count = fwye.length - 1;
                        for (var k = count; k >= 0; k--) {
                            str = str + "<tr><td>" + fwye[k].event_time + "</td><td>" + fwye[k].event_info + "</td></tr>";
                        }
                        $("#TBodyID_FWYEvent").html(str);
                    }, "json");
                }
            });

//-------------------------------GRID列函数-----------------------------------------------
            //右框查询
            function f_food_like_Select() {
                GRID.removeParm("order_code");
                GRID.removeParm("room_code");
                var room = $("#ID_room_code").val();
                var order_code = $("#ID_order_code").val();
                GRID.setParm("order_code", order_code);
                GRID.setParm("room_code", room);
                GRID.reload();
            }
            function f_viewOrderB(rowdata, rowid, rowobj) {
                GRID2.setParm("order_id", rowdata.order_id);
                GRID2.reload();
                f_viewOrder(rowdata.order_id);
            }
            function f_lockmyfood(oid, id, num) {
                if (post_json("view/buy/order/manager/fwy/u/uLockFood.imy", {bid: id, lockNum: num}, 200, 200)) {
                    GRID2.reload();
                    f_viewOrder(oid);
                }
            }
            function f_backmyfood(id, oid, fid) {
                if (post_json("view/buy/order/manager/fwy/u/backFood.imy",
                        {
                            bid: id
                            , backNum: -1
                            , order_id: oid
                            , food_id: fid
                        }, 200, 200)) {
                    GRID2.reload();
                    f_viewOrder(oid);
                }
            }
            function f_dellFWYOrderB(oid, bid) {
                if (post_json("view/buy/order/manager/fwy/d/dellLockFood.imy", {bid: bid}, 200, 200)) {
                    GRID2.reload();
                    f_viewOrder(oid);
                }
            }
            function f_dellBackFood(oid, id) {
                if (post_json("view/buy/order/manager/fwy/d/dellbackFood.imy", {bid: id}, 200, 200)) {
                    GRID2.reload();
                    f_viewOrder(oid);
                }
            }
            function f_songruChufang(oid) {
                if (post_json("view/buy/order/manager/fwy/u/songruChufang.imy", {order_id: oid}, 200, 200)) {
                    GRID2.reload();
                }
            }


//            view/buy/order/manager/fwy/u/songruChufang.imy

            function f_viewOrder(order_id) {
                $.post("view/buy/order/manager/fwy/s/selectOne.imy", {order_id: order_id}, function(data) {
                    var tr = "<tr>"
                            + "<td>" + data.order_code + "</td>"
                            + "<td>" + data.room_code + "</td>"
                            + "<td>" + data.order_sumprice + "</td>"
                            + "<td>" + data.user_account + "</td>"
                            + "<td><button onclick=\"printOrder('" + data.order_id + "')\">打印</button><button onclick=\"f_songruChufang('" + data.order_id + "')\">制作</button></td>"

                            + "</tr>";
                    $("#TR_SHOWDATA_ORDER").html(tr);
                }, "json");

            }



//-------------------------------增删改操作-----------------------------------------------
            function add() {
                ADD = openURL_Event("食物添加", ADD, "dc_manager/base/food/food_A.jsp", 400, 900, f_d);
                ADD.max();
                function f_d() {
                    ADD = null;
                    GRID.reload();
                }
            }
            function update() {
                var row = GRID.getSelectedRow();
                if (!row) {
                    msg_tip("错误", "请选择行");
                    return;
                } else if (row.food_id.length > 10) {
                    UPDATE = openURL_Event("食物修改", UPDATE, "weixinkeji/dev/dc/base/food/adu/update.imy?id=" + row.food_id, 400, 900, f_d);
                    UPDATE.max();
                }
                function f_d() {
                    UPDATE = null;
                    GRID.reload();
                }
            }
            function dell() {
                var rows = GRID.getSelectedRows();
                var ids = "";
                for (var i = 0; i < rows.length; i++) {
                    ids = ids + "," + rows[i].food_id;
                }
                ids = ids.substring(1);
                if (rows.length < 1) {
                    msg_tip("操作提示", "请选择行", 200, 50);
                    return;
                } else {
                    //view/buy/order/manager/fwy/u/uLockFood.imy
                    if (post_json("weixinkeji/dev/dc/base/food/adu/dell.imy", {"id": ids})) {
                        GRID.reload();
                        $("#SHOW_IMG_ID").attr("src", "");
                        $("#SHOW_IMG_HREF_ID").attr("href", "");
                        $("#showName").html("");
                        $("#IMG_food_id").val("");
                    }
                }
            }
            function dellAllEvent() {
                $.post("view/buy/order/manager/fwy/event/dellALl.imy");
                $("#TBodyID_FWYEvent").html("");
            }

            function printOrder(id) {
//                $("#printlnArea").printArea();
//            view/buy/order/manager/fwy/u/println.imy
                $.post("view/buy/order/manager/fwy/u/println.imy", {order_id: id});
            }
        </script>
    </head>
    <body>
        <div style="float: left; margin-left: 3px;">
            <div id="toptoolbar"></div> 
            <div id="divID_Select" style="margin: 5px;">
                <table style="font-size: 8px;">
                    <tr>
                        <td>房间</td><td><input id="ID_room_code"  size="9"  type="text" ></td>
                        <td>单号</td><td><input id="ID_order_code"  size="9" type="text" ></td>
                        <td><button onclick="f_food_like_Select();">查询</button></td>
                    </tr>
                </table>
            </div>
            <div id="divID_GRID"></div>
        </div>
        <div  style="float: left" id="printlnArea">
            <div>
                <table border="1">
                    <thead>
                        <tr>
                            <th width="120px">订单号</th><th width="50px">餐点</th><th width="80px">订单金额</th><th width="80px">下单人</th><th width="120px">操作</th>
                        </tr>
                    </thead>
                    <tbody id="TR_SHOWDATA_ORDER">
                        <tr>
                            <td>-</td><td></td><td></td><td></td>
                            <td>
                                <button onclick="printOrder('id')">打印</button>
                                <button onclick="printOrder('id')">结账</button>
                            </td>
                        </tr>
                    </tbody>
                </table>
            </div>
            <div id="divID_GRID2"></div>
        </div>
        <div style="float: left;font-size: 10px;">
            <div><button onclick="dellAllEvent()">清空事件</button></div>
            <div style="overflow:auto; height: 500px;">
                <table border="1" style="font-size: 14px;">
                    <thead>
                        <tr>
                            <th width="60px">时间</th><th width="110px">订单号/餐点/事件</th>
                        </tr>
                    </thead>
                    <tbody id="TBodyID_FWYEvent">

                    </tbody>
                </table>
            </div>
        </div>
    </div>
</body>
</html>
